package com.nbjtjc.safe.api.cost;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.model.cost.CostAccountReg;
import com.nbjtjc.safe.service.cost.CostAccountRegService;
import com.nbjtjc.safe.util.MyShiroUtils;

@RestController
@CrossOrigin("*")
@RequestMapping("/costAccountReg")
public class CostAccountRegController {
	@Autowired
	private CostAccountRegService costAccountRegService;


	  @RequestMapping(value = "/addOrUpdate",method = {RequestMethod.POST})
	  @SysLog("添加或更新安全投入预算计划项目")
	    public Result add(@RequestBody CostAccountReg costAccountReg){
	        Result result=new Result();
	        try {
	            result=costAccountRegService.add(costAccountReg);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }

	  
	  @RequestMapping(value = "/delete",method = {RequestMethod.POST})
	  @SysLog("删除安全投入预算计划项目")
	    public Result delete(@RequestBody CostAccountReg costAccountReg) {
	        Result result=new Result();
	        try {
	            result=costAccountRegService.delete(costAccountReg);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }

	  @RequestMapping(value = "/find", method = {RequestMethod.POST})
	  public Result find(@RequestBody CostAccountReg costAccountReg) {
	        Result result = new Result();

	        try {
	        	costAccountReg.setCompanyId(MyShiroUtils.getCompanyId());
	            result = costAccountRegService.find(costAccountReg);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
	  
	  @RequestMapping(value = "/findDetail", method = {RequestMethod.POST})
	  public Result findDetail(@RequestBody CostAccountReg costAccountReg) {
	        Result result = new Result();

	        try {
	            result = costAccountRegService.findDetail(costAccountReg);
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
	  
	  @RequestMapping(value = "/show", method = {RequestMethod.POST})
	  public Result show(@RequestBody CostAccountReg costAccountReg) {
	        Result result = new Result();

	        try {
	            result = costAccountRegService.show(costAccountReg.getId());
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
	  
	  @RequestMapping(value = "/searchByYear", method = {RequestMethod.POST})
	  public Result searchByYear(@RequestBody CostAccountReg costAccountReg) {
	        Result result = new Result();

	        try {
	            result = costAccountRegService.searchByYear(costAccountReg.getYear());
	        } catch (Exception e) {
	            e.printStackTrace();
	            result.setFalse(e.getMessage());
	        }
	        return result;
	    }
}
